<template>
    <div class="con">
        <my-head title="视频/MV"></my-head>
        <van-tabs v-model="active">
            <van-tab title="最新MV">
                <div v-if="flag" class="new">
                    <div v-for="(v,i) in arr" :key="i">
                        <video @play="stop=true" @pause="stop=false" controls :src="v.url"></video>
                        <p class="van-ellipsis">{{v.txt}} - {{v.name}}</p>
                    </div>
                </div>
            </van-tab>
            <van-tab title="全部MV">
                <div v-if="bool" class="new">
                    <div v-for="(v,i) in list" :key="i">
                        <video controls :src="v.url"></video>
                        <p class="van-ellipsis">{{v.txt}} - {{v.name}}</p>
                    </div>
                </div>
            </van-tab>
        </van-tabs>
    </div>
</template>

<script>
import { mapState,mapMutations } from "vuex";

export default {
    data(){
        return {
            active: 0,
            list:[],
            arr:[],
            flag:false,
            bool:false,
        }
    },
    computed:{
        stop:{
            get(){
                return this.$store.state.stop;
            },
            set(v){
                this.$store.commit('setStop',v)
            }
        }
    },
    mounted(){
        this.$ajax.getNewMv().then(res=>{
            res.data.forEach((item,i)=>{
                this.arr[i] = {name:item.artistName,txt:item.name,url:''}
                this.$ajax.getMvUrl({id:item.id}).then(result=>{
                    this.arr[i].url = result.data.url;
                    if(i>=this.arr.length-1){
                        this.flag = true
                    }
                })
            })
        })
        
        this.$ajax.getAllMv().then(res=>{
            res.data.forEach((item,i)=>{
                this.list[i] = {name:item.artistName,txt:item.name,url:''}
                this.$ajax.getMvUrl({id:item.id}).then(result=>{
                    this.list[i].url = result.data.url;
                    if(i>=this.list.length-1){
                        this.bool = true
                    }
                })
            })
        })
    }
}
</script>

<style lang="scss" scoped>
.con{
    padding-bottom: 95px;
}
.new{
    width: 100%;
    margin-bottom: 10px;
    background: #eee;
    p{
        margin-top: -2px;
        padding:10px 20px;
        margin-bottom: 20px;
        background: #fff;
        color: #333;
        font-size: 16px;
    }
}
video{
    width: 100%;
}
</style>